import pandas
df = pandas.read_csv('D:\ProgramFile2_OR\Python_study\mathorcup2024C\附件\附件1.csv',encoding = 'utf-8')
df['日期'] = pandas.to_datetime(df['日期'])

# print(df.head(15))
sortNum = [int(item[2:]) for item in df['分拣中心']] 
df['asSort'] = sortNum
# print(df.head(10))

select_sort = df.sort_values(by = 'asSort').reset_index(drop = True)
data_sort = select_sort.groupby('asSort').apply(lambda x: x.sort_values(by = '日期').reset_index(drop = True))
data_sorted = data_sort.drop(['asSort'],axis = 1)
print(data_sorted.head(10))
data_sorted.to_csv(r"D:\ProgramFile2_OR\Python_study\mathorcup2024C\sortData_Fujian1.csv", index=False, encoding='utf-8')

# print(data_sorted.iloc[124:135,:])
